usingnamespacestd; constint INF = 0x3f3f3f3f; int ma[102][102]; int n, m; voidfloyd(){ for (int k = 1; k <= n; ++k) for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) if ((ma[i][k] == 1 || ma[i][k] == -1) && ma[i][k] == ma[k][j]) ma[i][j] = ma[i][k]; } intmain(){ cin >> n >> m; memset(ma, INF, sizeof ma); for (int i = 1; i <= n; ++i) ma[i][i] = 0; while(m--){ int u, v; cin >> u >> v; ma[u][v] = 1; ma[v][u] = -1; } floyd(); int ans = 0; for (int i = 1; i <= n; ++i){ int flag = 1; for (int j = 1; j <= n; ++j){ if (ma[i][j] == INF){ flag = 0; break; } } if (flag) ans++; } cout << ans << "\n"; }